package ControlLayer;
import java.util.ArrayList;
import ModelLayer.*;//model layer package has to be imported
/**
 * Controller class for the address book
 * 
 * @author (kbh) 
 * @version (2005.03.31)
 * (FEN): 2006.03.21: Some changes to the architecture in order to assure layering
 *                    and loose coupling
 */
public class AddressCtr
{
    
   private  AddressBook addressBook; //declare instance variables to reference containers
                                    //passed as arguments from the main class
 

    //Address container is to be passed as parameter from the main controller
   public AddressCtr()
    {
       addressBook = AddressBook.getInstance();
    }

    
    
    
   public Person getPerson(String id)
   {
        return addressBook.findPerson(id);
            
   }
        
   public String printPerson(String id)
   {
       return addressBook.findPerson(id).toString();
   }
       
       

  
        
    
    
    public void createPerson(String id, String name, String address, String postalCode, String city, String phone)
    {
        if(getPerson(id)!=null){
            System.out.println("Person with ID: "+id+" already exists.");
        }else{
            //creates a Person object and stores it in the container
            addressBook.setPerson(id, name, address, postalCode, city, phone); 
        }
    }
    
    public void deletePerson(String id)
    {
            addressBook.deletePerson(id);
    }
    
    public void updatePerson(String id, String name, String address, String postalCode, String city, String phone)
    {
        addressBook.editPerson(getPerson(id),  name,  address,  postalCode,  city,  phone );
        
    }
    
    public ArrayList<Person> listAllPersons()
    {
         if(addressBook.getPerson().isEmpty()){
               System.out.println("Address book is empty.");
         }
          return addressBook.getPerson();
    }
}
